<?php
	if(!isset($operation) || $operation == 'manage' || $operation == ''){
		$re = C::t('common_contact')->get_all_info();
		echo '<table border="3" style="width:100%"><tr><td width="10%">栏目名称</td><td width="80%">栏目内容</td><td>操作</td></tr>';
		foreach($re as $key=>$val){
			echo '<tr><td>'.$val['name'].'</td><td>'.mb_substr( strip_tags($val['content']), 0, 150, 'utf-8' ).'</td><td><a href="admin.php?action=contactinfo&operation=edit&id='.$val['id'].'">编辑</a></td></tr>';
		}
		echo '</table>';
?>
	
<?php 
	}else if($operation == 'edit'){
		$info = C::t('common_contact')->get_info($_GET['id']);
?>
		<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
	    <script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.min.js"> </script>
	    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
	    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
	    <script type="text/javascript" charset="utf-8" src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>

	    <style type="text/css">
	        div{
	            width:100%;
	        }
	    </style>
	    <div>
	    <?php showformheader('contactinfo&operation=checkedit');?>
		    	<table cellspacing="9">
		    		<input type="hidden" name="id" value="<?php echo $info['id']?>">
		    		<tr>
		    			<th>栏目名称：</th>
		    			<td><input type="text" name="name" value="<?php echo $info['name']?>"></td>
		    		</tr>
		    		<tr>
		    			<th>栏目内容：</th>
		    			<td><textarea name="content" id="editor" type="text/plain" style="width:600px;height:200px;"><?php echo $info['content']?></textarea></td>
		    		</tr>
		    		<tr>
		    			<td colspan="2"><input type="submit" value="保存"></td>
		    		</tr>
		    	</table>
		    </form>
		</div>

		<script type="text/javascript">

		    //实例化编辑器
		    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
		    var ue = UE.getEditor('editor');


		    function isFocus(e){
		        alert(UE.getEditor('editor').isFocus());
		        UE.dom.domUtils.preventDefault(e)
		    }
		    function setblur(e){
		        UE.getEditor('editor').blur();
		        UE.dom.domUtils.preventDefault(e)
		    }
		    function insertHtml() {
		        var value = prompt('插入html代码', '');
		        UE.getEditor('editor').execCommand('insertHtml', value)
		    }
		    function createEditor() {
		        enableBtn();
		        UE.getEditor('editor');
		    }
		</script>
<?php 
	}else if($operation == 'checkedit'){
		$name = trim($_POST['name']);
		$content = trim($_POST['content']);
		C::t('common_contact')->edit_info($name, $content, $_POST['id']);
		echo '<script type="text/Javascript">alert("修改成功!");';
		echo 'window.location="'.ADMINSCRIPT.'?action=contactinfo&operation=manage";';
		echo '</script>';
	}
?>